<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

</body>
<script>
  // navigator   window.navigator    //设备相关的信息

  // 属性
  // navigator.userAgent  用户代理信息，通过该属性可以获取浏览器及操作系统信息

  // PC:  Windows  Mac 
  // 移动: iPhone iPad Android BB10

  // console.log(navigator);
  // console.log(navigator.userAgent);

  // document.write(navigator.userAgent);


  // 判断设备是否是移动端 ? 
  // PC    jd.com
  // 移动端 m.jd.com

  var userAgent = navigator.userAgent;
  var appList = ["iPhone", "iPad", "Android", "BB10"];

  var flag = false; //假设不是移动端
  for (var i = 0; i < appList.length; i++) {
    var app = appList[i];
    if (userAgent.includes(app)) {
      flag = true;
      break;
    }
  }

  if (flag) {
    document.write("移动端:" + app);
  } else {
    document.write("PC端");
  }




</script>

</html>